<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var getStrongest = function (arr, k) {
      arr.sort((a, b) => a - b);
      let m = arr[Math.floor((arr.length - 1) / 2)];
      arr.sort((a, b) => {
        let aa = Math.abs(a - m);
        let bb = Math.abs(b - m);
        return aa === bb ? b - a : bb - aa;
      });
      return arr.slice(0, k);
    }
    console.log(getStrongest([1, 2, 3, 4, 5], 2));
  </script>
</body>

</html>